package com.example.springbooteasycode.zjrc.project.Koal;

import java.util.Arrays;

public class HexToByte {
    public static void main(String[] args) {
//        String hex = "004D6AB6FFFFFFFFFFFFFFFF00000000021019909920579701000539891349E2E2CE560200000025000000000002000000000000015600000000000156250226008274E7F57C00000503A00000F0F0";
        String hex = "";
        byte[] bytes = hexStringToByteArray(hex);
        System.out.println(Arrays.toString(bytes));

    }

    public static byte[] hexStringToByteArray(String hex) {
        int len = hex.length();
        byte[] data = new byte[len / 2];

        for (int i = 0; i < len; i += 2) {
            // 每两个字符解析为一个字节
            data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
                    + Character.digit(hex.charAt(i+1), 16));
        }

        return data;
    }
}
